package com.zcmob.web.admanagement.servlet;


import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zcmob.web.admanagement.db.AppDao;
import com.zcmob.web.admanagement.vo.AdUser;
import com.zcmob.web.admanagement.vo.AdvInfo;

public class NewAdvServlet extends ZcMobServlet{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    protected void handle(HttpServletRequest req, HttpServletResponse response) {
        // TODO Auto-generated method stub
        try {
            String name = req.getParameter("name");
            String phone = req.getParameter("phone");
            String telephone = req.getParameter("telephone");
            String email = req.getParameter("email");
            String site = req.getParameter("site");
            String address = req.getParameter("address");
            String zip = req.getParameter("zip");
            String comment = req.getParameter("comment");
            int creater = ((AdUser)req.getSession().getAttribute("aduser")).getId();
            
            AdvInfo info = new AdvInfo();
            info.setAddress(address);
            info.setComment(comment);
            info.setEmail(email);
            info.setName(name);
            info.setPhone(phone);
            info.setSite(site);
            info.setTelephone(telephone);
            info.setZip(zip);
            info.setCreater(creater);
            
            AppDao.getInstance().insertAdv(info);
            
            RequestDispatcher rd = req.getRequestDispatcher("s_advlist");
            rd.forward(req, response);
        
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
}
